
Array.prototype.maximo = function() {
var max = this[0];
var len = this.length;
for (var i = 1; i < len; i++) if (this[i] > max) max = this[i];
return max;
}


function barra_h(pos_genX, pos_genY, tope, grosor, stepscala, serie1, labels, color, paper) {
	var cant_grps = serie1.length;
	var maximo = serie1.maximo();

	for (i=0;i<cant_grps;i++){
	valor1 = serie1[i]*tope/maximo;
	var c = paper.rect((pos_genX+(grosor*i)), pos_genY, grosor/3, 0); 
	var c2 = paper.rect((pos_genX+(grosor*i)+(grosor/3)), pos_genY, grosor*2/3, 0); 

	var t = paper.text( pos_genX+(grosor*i)+(grosor/2), (pos_genY+15), serie1[i]); t.attr("font-size", "12"); 

	c.attr("fill", "0-#000-"+color[i]); c2.attr("fill", "0-"+color[i]+"-#000");
	c.attr("stroke-width", "0"); c2.attr("stroke-width", "0");
	c.animate({height:valor1}, 1000); c2.animate({height:valor1}, 1000);
	c.animate({y:pos_genY-valor1}, 1000); c2.animate({y:pos_genY-valor1}, 1000);

	}

	var c = paper.rect((pos_genX-50), pos_genY-(tope+20), 1, (tope+20)); 

	for (i=0;i<=tope;i = i +stepscala){
	var labelvalor = i*maximo/tope;
	var c = paper.rect((pos_genX-50), pos_genY-i, 15, 1); 
	var t = paper.text((pos_genX-70), pos_genY-i, labelvalor.toFixed(0));
	}

	for (i=0;i<cant_grps;i++){
	var c = paper.rect((pos_genX+80+(grosor*cant_grps)), ((pos_genY/3) + (i*20) - 5), 10, 10); c.attr("fill", color[i]);
	var t = paper.text((pos_genX+100+(grosor*cant_grps)) , ((pos_genY/3) + (i*20)), labels[i]); t.attr("font-size", "14"); t.attr("text-anchor", "start");
	}

}




function grafica_piramide1(pos_genX, pos_genY, tope, grosor, stepscala, grps_serie, tit_gprs, serie1, tit_serie1, color_s1, serie2, tit_serie2, color_s2, paper) {
var cant_grps = serie1.length;
var ancho = (tope * 2)+40;
var maximo = 100;
if (serie1.maximo() > serie2.maximo()) maximo = serie1.maximo();
if (serie2.maximo() > serie1.maximo()) maximo = serie2.maximo();


for (i=0;i<cant_grps;i++){
valor1 = serie1[i]*tope/maximo;
valor2 = (serie2[i]*tope/maximo);
var t = paper.text(pos_genX+40, (pos_genY+(grosor*i)+(grosor/2)), grps_serie[i]);t.attr("font-size", "14");

var c = paper.rect((pos_genX + tope + 100), (pos_genY+(grosor*i)), valor1, grosor/3); c.attr("fill", "90-"+color_s1+"-#000"); c.attr("stroke-width", "0"); 
var c = paper.rect((pos_genX + tope + 100), (pos_genY+(grosor*i)+(grosor/3)), valor1, 1); c.attr("fill", "90-#000-"+color_s1); c.attr("stroke-width", "0"); c.animate({height:grosor*2/3}, 1000);


var c2 = paper.rect((pos_genX + tope + 100)-valor2, (pos_genY+(grosor*i)), valor2, grosor/3); c2.attr("fill", "90-"+color_s2+"-#000");c2.attr("stroke-width", "0");
var c2 = paper.rect((pos_genX + tope + 100)-valor2, (pos_genY+(grosor*i)+(grosor/3)), valor2, 1); c2.attr("fill", "90-#000-"+color_s2);c2.attr("stroke-width", "0"); c2.animate({height:grosor*2/3}, 1000);
}

var t = paper.text(pos_genX, pos_genY+((grosor*(i*1))/2), tit_gprs);t.attr("font-size", "14"); t.attr("rotation", "270");

var ypos = pos_genY+((grosor*(i*1))+8);

for (i=0; i<=tope; i=i+stepscala){
var labelvalor = (i*maximo/tope);
var t = paper.text((pos_genX + tope + 100)+i, (pos_genY-20)+(grosor * (cant_grps+2))+10, labelvalor.toFixed(0) ); 
var t = paper.text((pos_genX + tope + 100)-i, (pos_genY-20)+(grosor * (cant_grps+2))+10, labelvalor.toFixed(0) );
var l = paper.rect((pos_genX + tope + 100)+i, (pos_genY-20), 0.2, grosor * (cant_grps+2)); l.attr("stroke-width", "0.2"); l.toBack(); 
var l = paper.rect((pos_genX + tope + 100)-i, (pos_genY-20), 0.2, grosor * (cant_grps+2)); l.attr("stroke-width", "0.2"); l.toBack(); 
}

var t = paper.text((pos_genX + 80)+(ancho/3), ypos+(grosor*3), tit_serie2);t.attr("font-size", "14");
var t = paper.text((pos_genX + 80)+(ancho*2/3), ypos+(grosor*3), tit_serie1);t.attr("font-size", "14");

var fondo = paper.rect((pos_genX + 80), (pos_genY-20), ancho, grosor * (cant_grps+2)); 
fondo.attr("fill", "90-#fff-#ffffcc"); 

fondo.toBack(); 
}

function barrasVerticales(pos_genX, pos_genY, tope, grosor, serie, color, paper){

	maximo = serie[0]+serie[1];
	valor1 = serie[0]*tope/maximo;
	valor2 = serie[1]*tope/maximo;
	
	var c = paper.rect( pos_genX, pos_genY,  0,grosor/3); 
	c.attr("fill", "90-"+color[0]+"-#000");
	c.attr("stroke-width", "0");
	
	var c2 = paper.rect( pos_genX, pos_genY+(grosor/3),  0,grosor *2/3); 
	c2.attr("fill", "90-#000-"+color[0]);
	c2.attr("stroke-width", "0");
	
	var c3 = paper.rect( pos_genX, pos_genY+grosor,  0,grosor/3); 
	c3.attr("fill", "90-"+color[1]+"-#000");
	c3.attr("stroke-width", "0");

	var c4 = paper.rect( pos_genX, pos_genY+grosor*4/3,  0,grosor *2/3); 
	c4.attr("fill", "90-#000-"+color[1]);
	c4.attr("stroke-width", "0");
	
	c.animate({width:valor1}, 1000); 
	c2.animate({width:valor1}, 1000);
	
	c3.animate({width:valor2}, 1000); 
	c4.animate({width:valor2}, 1000);
	//c3.animate({x:pos_genY}, 1000); c4.animate({x:pos_genY}, 1000);
	
//	var t = paper.text( pos_genX+(valor1/2), (pos_genY+grosor+15), serie[0]); t.attr("font-size", "12"); 
//	var t = paper.text( pos_genX+valor1+(valor2/2), (pos_genY+grosor+15), serie[1]); t.attr("font-size", "12"); 
	
//	var t = paper.text( pos_genX+(valor1/2), (pos_genY+grosor+15), labels[0]+" ("+serie[0]+")"); t.attr("font-size", "14"); t.attr("rotation", "45");
//	var t = paper.text( pos_genX+valor1+(valor2/2), (pos_genY+grosor+15), labels[1]+" ("+serie[1]+")"); t.attr("font-size", "14"); t.attr("rotation", "45");

}


function stake_hbar_sensilla(pos_genX, pos_genY, tope, grosor, serie, color, paper){

	maximo = serie[0]+serie[1];
	valor1 = serie[0]*tope/maximo;
	valor2 = serie[1]*tope/maximo;
	
	var c = paper.rect( pos_genX, pos_genY,  0,grosor/3); 
	var c2 = paper.rect( pos_genX, pos_genY+(grosor/3),  0,grosor *2/3); 
	c.attr("fill", "90-"+color[0]+"-#000"); c2.attr("fill", "90-#000-"+color[0]);
	c.attr("stroke-width", "0"); c2.attr("stroke-width", "0");
	
	var c3 = paper.rect( pos_genX, pos_genY,  0,grosor/3); 
	var c4 = paper.rect( pos_genX, pos_genY+(grosor/3),  0,grosor *2/3); 
	c3.attr("fill", "90-"+color[1]+"-#000"); c4.attr("fill", "90-#000-"+color[1]);
	c3.attr("stroke-width", "0"); c4.attr("stroke-width", "0");
	
	c.animate({width:valor1}, 1000); c2.animate({width:valor1}, 1000);
	c3.animate({width:valor2}, 1000); c4.animate({width:valor2}, 1000);
	c3.animate({x:valor1+pos_genX}, 1000); c4.animate({x:valor1+pos_genX}, 1000);
	
	var t = paper.text( pos_genX+(valor1/2), (pos_genY+grosor+15), serie[0]); t.attr("font-size", "12"); 
	var t = paper.text( pos_genX+valor1+(valor2/2), (pos_genY+grosor+15), serie[1]); t.attr("font-size", "12"); 
	
//	var t = paper.text( pos_genX+(valor1/2), (pos_genY+grosor+15), labels[0]+" ("+serie[0]+")"); t.attr("font-size", "14"); t.attr("rotation", "45");
//	var t = paper.text( pos_genX+valor1+(valor2/2), (pos_genY+grosor+15), labels[1]+" ("+serie[1]+")"); t.attr("font-size", "14"); t.attr("rotation", "45");

}
